/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-09-06
 * Time: 22:46
 */
public class Test90 {
    public static void main(String[] args) {
        int[] nums = {2,3,-2,4};
        int ret = maxProduct(nums);
        System.out.println(ret);
    }
    public static int maxProduct(int[] nums) {
        int n  = nums.length;
        int[] f = new int[n+1];
        int[] g = new int[n+1];
        f[0] = 1;
        g[0] = 1;
        int ret = Integer.MIN_VALUE;
        for(int i = 1; i <= n; i++) {
            int x = nums[i-1], y = f[i-1]*x, z = g[i-1]*x;
            f[i] = Math.max(x,Math.max(z,y));
            g[i] = Math.min(x,Math.min(y,z));
            ret = Math.max(f[i],ret);
        }
        return ret;
    }
}
